package code.example.zookeeper.api;

import org.apache.zookeeper.Watcher;

public class EventTypeAPI {
     enum EventType{
         /**
          *  zk 连接成功时的类型
          */
        None (-1),
         /**
          * 节点被创建事件
          *  create 方法触发。
          *  exists:方法设置的watcher接收事件
          *  getChildren:方法设置的watcher接收事件
          *
          */
        NodeCreated (1),
         /**
          * 节点被删除事件
          *  delete 方法触发
          *  exists:方法设置的watcher接收事件
          *  getChildren:方法设置的watcher接收事件
          *  getData:方法设置的watcher接收事件
          */
        NodeDeleted (2), //节点删除事件
         /**
          * 节点数据改变事件
          *   setData 方法触发
          *    exists:方法设置的watcher接收事件
          *    getData:方法设置的watcher接收事件
          */
        NodeDataChanged (3),//节点数据改变事件
         /**
          *  子节点改变事件
          *   create方法触发
          *   delete 方法触发
          *
          *   getChildren:方法设置的watcher接收事件
          */
        NodeChildrenChanged (4);//子节点改变事件
        EventType(int i){}
    }
    public enum KeeperState {


        /** The client is in the disconnected state - it is not connected
         * to any server in the ensemble.
         * 断开连接
         * */
        Disconnected (0),

        /** The client is in the connected state - it is connected
         * to a server in the ensemble (one of the servers specified
         * in the host connection parameter during ZooKeeper client
         * creation).
         * 已连接zookeepr server
         *
         * */
        SyncConnected (3),

        /**
         * Auth failed state
         *  授权失败
         */
        AuthFailed (4),

        /**
         * The client is connected to a read-only server, that is the
         * server which is not currently connected to the majority.
         * The only operations allowed after receiving this state is
         * read operations.
         * This state is generated for read-only clients only since
         * read/write clients aren't allowed to connect to r/o servers.
         * 只读方式已连接
         */
        ConnectedReadOnly (5),

        /**
         * SaslAuthenticated: used to notify clients that they are SASL-authenticated,
         * so that they can perform Zookeeper actions with their SASL-authorized permissions.
         */
        SaslAuthenticated(6),

        /** The serving cluster has expired this session. The ZooKeeper
         * client connection (the session) is no longer valid. You must
         * create a new client connection (instantiate a new ZooKeeper
         * instance) if you with to access the ensemble.
         *  session 过期
         * */
        Expired (-112);

        private final int intValue;     // Integer representation of value
        // for sending over wire

        KeeperState(int intValue) {
            this.intValue = intValue;
        }


    }
}
